package com.yc.meeting_attendance.adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.yc.meeting_attendance.R;

import java.util.ArrayList;
import java.util.List;

public class Gallery_adapter extends BaseAdapter {
	
	Context context;
	
	List<String> list;

	public Gallery_adapter(Context context ,List<String> list) {
		this.context = context;
		this.list=list;
	}
	public void clear(){
		if(null!=this.list){
			this.list.clear();
		}
		this.notifyDataSetChanged();
	}



	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder = null;
		if(convertView == null || convertView.getTag() == null){
			convertView = LayoutInflater.from(context).inflate(R.layout.gallery_item, parent,false);
			
			viewHolder = new ViewHolder();
			
			viewHolder.gallery_iv = (ImageView) convertView.findViewById(R.id.gallery_iv);

			
			convertView.setTag(viewHolder);
			
		}else{
			viewHolder = (ViewHolder) convertView.getTag();
		}
		Log.w("wwhhh","list-size-"+list.size()+"position-" + position);


		if(list!=null && list.size()>0){
			Glide.with(context).load(list.get(position)).into(viewHolder.gallery_iv);
		}
//		viewHolder.gallery_iv.setImageResource(Integer.parseInt(list.get(position).toString()));
		return convertView;
	}
	
	class ViewHolder{
		ImageView gallery_iv;
	}

}
